unit oEditorGeneratorManager;

interface

uses
  oManager, oFormGenerator, oProcessItem, SysUtils;

type
  EGeneratorEditorManagerException = class(Exception)
  end;

  TEditorGeneratorManager = class(TManager)
    private
      aForm: TfrmGenerator;
    public
      constructor create(paMaster: TManager);
      destructor Destroy; override;
      function ProcessObject(paItem: TProcessItem):TProcessItem;
  end;

implementation

uses
  oProcessObjectConstants, oProcessObjects;

resourcestring eGenEdManNotValidConstant = 'not a valid constant';
resourcestring eGenEdManNotValidType = 'not a valid type';

{ TGeneratorEditorManager }

constructor TEditorGeneratorManager.create(paMaster: TManager);
begin
  inherited create(paMaster);
  aForm := nil;
end;

destructor TEditorGeneratorManager.Destroy;
begin
  aForm.Free;
  inherited;
end;

function TEditorGeneratorManager.ProcessObject(
  paItem: TProcessItem): TProcessItem;
begin
  if not(paItem.Data is TProcessingGeneratorData) then raise EGeneratorEditorManagerException.Create(eGenEdManNotValidType);
  with paItem.Data as TProcessingGeneratorData do
    case paItem.Code of
      PO_GET_GENERATOR: begin
        aForm := TfrmGenerator.Create(nil);
        aForm.Show(Data);
        result := TProcessItem.create(PO_SUCCESS,TProcessingGeneratorData.create(aForm.Data));
        aForm.Free;
        aForm := nil;
        paItem.Free;
      end
      else raise EGeneratorEditorManagerException.Create(eGenEdManNotValidConstant);
  end;

end;

end.
